import { createRouter, createWebHistory } from 'vue-router'

// 通用页面：不需要守卫，可直接访问
export const constRoutes = [
  {
    path: "/",
    redirect: '/home',
    component: () => import("@/views/Home"),
    children: [
      {
        path: "/home",
        name: 'home',
        meta: {
          title: "首页",
          icon: "home"
        },
        component: () => import("@/views/home/HomePage"),
      }
    ]
  },
  {
    path: "/echarts",
    name: 'echarts',
    redirect: '/echarts/bar',
    component: () => import("@/views/Home"),
    meta: {
      title: "ECharts 图表",
      icon: "echarts"
    },
    children: [
      {
        path: "/echarts/bar",
        name: 'bar',
        meta: {
          title: "饼图",
          icon: "bar"
        },
        component: () => import("@/views/echarts/Bar"),
      },
      {
        path: "/echarts/sctter",
        name: 'sctter',
        meta: {
          title: "散点图",
          icon: "sctter"
        },
        component: () => import("@/views/echarts/Sctter"),
      },
      {
        path: "/echarts/ring",
        name: 'ringbar',
        meta: {
          title: "环形图",
          icon: "ring"
        },
        component: () => import("@/views/echarts/RingDiagram"),
      },
      {
        path: "/echarts/map3d",
        name: 'map3d',
        meta: {
          title: "三维地图",
          icon: "map3d"
        },
        component: () => import("@/views/echarts/Map3D"),
      },
      {
        path: "/echarts/map2d",
        name: 'map2d',
        meta: {
          title: "二维地图",
          icon: "map2d"
        },
        component: () => import("@/views/echarts/Map2D"),
      }
    ]
  },
  {
    path: "/editor",
    name: 'editor',
    redirect: '/editor/richtext',
    component: () => import("@/views/Home"),
    meta: {
      title: "编辑器",
      icon: "editor"
    },
    children: [
      {
        path: "/editor/richtext",
        name: 'richtext',
        meta: {
          title: "富文本编辑器",
          icon: "richtext"
        },
        component: () => import("@/views/editor/TEditor"),
      },
      {
        path: "/editor/code",
        name: 'code',
        meta: {
          title: "代码编辑器",
          icon: "code"
        },
        component: () => import("@/views/editor/CodeEditor"),
      },
      {
        path: "/editor/markdown",
        name: 'markdown',
        meta: {
          title: "MarkDown 编辑器",
          icon: "markdown"
        },
        component: () => import("@/views/editor/MarkDownEditor"),
      },
      {
        path: "/editor/svg",
        name: 'svg',
        meta: {
          title: "SVG 编辑器",
          icon: "markdown"
        },
        component: () => import("@/views/editor/SvgEditor"),
      },
      {
        path: "/editor/word",
        name: 'word',
        meta: {
          title: "生成Word文档",
          icon: "markdown"
        },
        component: () => import("@/views/editor/CreateWordDocx"),
      }
    ]
  },
  {
    path: "/map",
    name: 'map',
    redirect: '/map/controls',
    component: () => import("@/views/Home"),
    meta: {
      title: "WEBGIS",
      icon: "webgis"
    },
    children: [
      {
        path: "/map/controls",
        name: 'controls',
        meta: {
          title: "地图控件",
          icon: "controls"
        },
        component: () => import("@/views/webgis/MapControls"),
      },
      {
        path: "/map/vectorsource",
        name: 'vectorsource',
        meta: {
          title: "多源数据",
          icon: "vectorsource"
        },
        component: () => import("@/views/webgis/MapVectorSource"),
      },
      {
        path: "/map/baidutile",
        name: 'baidutile',
        meta: {
          title: "地图瓦片",
          icon: "baidutile"
        },
        component: () => import("@/views/webgis/BaiDuTile"),
      },
      {
        path: "/map/heatmap",
        name: 'heatmap',
        meta: {
          title: "热力图",
          icon: "heatmap"
        },
        component: () => import("@/views/webgis/Heatmap"),
      },
      {
        path: "/map/marker",
        name: 'marker',
        meta: {
          title: "Marker标注",
          icon: "marker"
        },
        component: () => import("@/views/webgis/Marker"),
      },
      {
        path: "/map/popup",
        name: 'popup',
        meta: {
          title: "Popup标注",
          icon: "popup"
        },
        component: () => import("@/views/webgis/Popup"),
      },
      {
        path: "/map/drivers",
        name: 'drivers',
        meta: {
          title: "视图联动",
          icon: "drivers"
        },
        component: () => import("@/views/webgis/DriversView"),
      },
      {
        path: "/map/navigation",
        name: 'navigation',
        meta: {
          title: "地图导航",
          icon: "navigation"
        },
        component: () => import("@/views/webgis/MapNavigation"),
      },
      {
        path: "/map/charts",
        name: 'charts',
        meta: {
          title: "热区图表",
          icon: "charts"
        },
        component: () => import("@/views/webgis/MapECharts"),
      },
      {
        path: "/map/line",
        name: 'line',
        meta: {
          title: "地图画线",
          icon: "line"
        },
        component: () => import("@/views/webgis/MapLine"),
      },
    ]
  },
  {
    path: "/login",
    component: () => import("@/views/Login"),
    hidden: true // 导航菜单忽略该项
  },
  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true // 导航菜单忽略该项
  }
]

// 权限页面：受保护页面，要求用户登录并拥有访问权限的角色才能访问
export const asyncRoutes = [
  {
    path: "/authority",
    name: 'authority',
    redirect: '/authority/AuthorityOne',
    component: () => import("@/views/Home"),
    meta: {
      title: "权限页面",
      icon: "authority",
      roles: ['admin']
    },
    children: [
      {
        path: "/authority/AuthorityOne",
        name: 'AuthorityOne',
        meta: {
          title: "权限页面1",
          icon: "AuthorityOne"
        },
        component: () => import("@/views/authority/AuthorityOne"),
      },
      {
        path: "/authority/AuthorityTwo",
        name: 'AuthorityTwo',
        meta: {
          title: "权限页面2",
          icon: "AuthorityTwo"
        },
        component: () => import("@/views/authority/AuthorityTwo"),
      }
    ]
  }
]

export default createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes: constRoutes
})